﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CI;
using System.Data.SqlClient;
using System.Data;
using CI.Caja.BE;

namespace CI.Caja.DL
{
    public class DA_Orden : IDA_Orden
    {
        DA_Utilitario objUtility = new DA_Utilitario();
        public BE_Orden ObtenerOrden(BE_Orden prmOrdenBE)
        {
            SqlConnection cnx = new SqlConnection(DA_Utilitario.ObtenerConexion());
            try
            {
                cnx.Open();
                SqlCommand cmd = new SqlCommand("SP_SEL_ORDEN", cnx);
                cmd.CommandType = CommandType.StoredProcedure;

                var _with1 = (cmd.Parameters);
                _with1.Add("@NroOrden", SqlDbType.VarChar,10).Value = prmOrdenBE.NroOrden;


                BE_Orden objOrdenBE = new BE_Orden();
                SqlDataReader reader = default(SqlDataReader);

                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    objOrdenBE.Descripcion = reader.GetString(reader.GetOrdinal("txtDescripcion"));
                    objOrdenBE.Fecha = reader.GetDateTime(reader.GetOrdinal("fecFecha"));
                    objOrdenBE.IdPaciente = reader.GetString(reader.GetOrdinal("IdPaciente"));
                    objOrdenBE.ImporteTotal = reader.GetDecimal(reader.GetOrdinal("numImporteTotal"));
                    objOrdenBE.NroOrden = reader.GetString(reader.GetOrdinal("NroOrden"));
                }

                return objOrdenBE;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cnx.Close();
            }
        }
    }
}
